$().ready(function() {
	initDictDatas();
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
//构建字典数据
function initDictDatas(){
	
	var thatDictFields = window.parent.dictFields;
	var thatDictkeys = window.parent.dictKeys;
	var thatDictDatas = window.parent.dicDatas;
	
	$('#typeCode').bootstrapSelect({
		data:thatDictDatas['typeCode'],
		valueField: 'value',
		textField: 'name',
		placeholder: "请选择优惠券类型"
	});
	$('#typePlat').bootstrapSelect({
		data:thatDictDatas['typePlat'],
		valueField: 'value',
		textField: 'name',
		placeholder: "请选择应用类型"
	});
}
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx+"plat/cpType/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			}else if(data.code == 2){
				parent.layer.alert(data.msg);
			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			}
		}
	})
}